<?php
namespace app\common\library\traits;
use think\Request;
use think\Db;
trait Log
{
	/**
    * 添加操作日志
    */
    protected function addOperLog()
    {
    	$module = strtolower(Request()->module());
		$controller = strtolower(Request()->controller());
		$action = strtolower(Request()->action());
    	$func_name = '/' . $module . '/' . $controller . '/' . $action;
    	$logData = $this->getTableName($func_name);
    	if($logData){
    		$data = [
	    		'admin_id'		=> session('admin.admin_id'),
                'shop_id'       => session('admin.shop_id'),
	    		'table_name'	=> $logData[0],
	    		'id'			=> $this->log_id,
	    		'func_name'		=> $func_name,
	    		'event'			=> $logData[1],
	    		'content'		=> $logData[2],
	    		'addtime'		=> time(),
	    	];
	    	Db::name('operation_log')->insert($data);
    	}
    }
    /**
    * 操作的表名
    */
    protected function getTableName($name)
    {
    	switch($name){
    		/*@维修单*/
    		case '/repair/repair/repair_add': switch($this->log_ty){
    			case 0: return ['mps_repair','【添加】','【维修单保存】'];break;
    			case 3: return ['mps_repair','【添加】','【维修单确认维修】'];;break;
    			default: return [];break;
    		}
    		case '/repair/repair/update_repair_state': switch($this->log_ty){
    			case 1: return ['mps_repair','【编辑】','【维修单等待配件】'];break;
    			case 2: return ['mps_repair','【编辑】','【维修单等待送机】'];break;
    			case 3: return ['mps_repair','【编辑】','【维修单待维修】'];break;
    			case 4: return ['mps_repair','【编辑】','【维修单维修中】'];break;
    			case 5: return ['mps_repair','【编辑】','【维修单修外送】'];break;
    			case 6: return ['mps_repair','【编辑】','【维修单待取机】'];break;
    			case 7: return ['mps_repair','【编辑】','【维修单退款并取机】'];break;
    			case 8: return ['mps_repair','【编辑】','【维修单付款并取机】'];break;
    			case 9: return ['mps_repair','【编辑】','【维修单维修失败】'];break;
    			default: return [];break;
    		}
    		case '/repair/repair/up_money': return ['mps_repair','【编辑】','【编辑维修金额】'];break;
    		case '/repair/repair/repair_edit':
    		case '/repair/repair/main_repair_edit':
    		return ['mps_repair','【编辑】','【编辑维修信息】'];break;
            /*@维修单缺货采购*/
            case '/repair/goods/purchase': return ['mps_purchase_order','【添加】','【维修单缺货采购】'];
    		/*@维修分类/故障/描述信息*/
    		case '/repair/fault/del': return ['mps_fault','【删除】','【删除】'];break;
    		case '/repair/fault/add': switch($this->log_ty){
    			case 0: return ['mps_fault','【添加】','【添加维修设备】'];break;
    			case 1: return ['mps_fault','【添加】','【添加维修故障】'];;break;
    			case 2: return ['mps_fault','【添加】','【添加维修描述】'];;break;
    			default: return [];break;
    		}
    		case '/repair/fault/edit': switch($this->log_ty){
    			case 0: return ['mps_fault','【编辑】','【编辑维修设备】'];break;
    			case 1: return ['mps_fault','【编辑】','【编辑维修故障】'];;break;
    			case 2: return ['mps_fault','【编辑】','【编辑维修描述】'];;break;
    			default: return [];break;
    		}
    		/*@维修提成设置*/
    		case '/repair/ratio/index': return ['mps_repair_ratio','【编辑】','【维修提成设置】'];break;
    		/*@维修配件返库*/
    		case '/repair/stock/return_house': return ['mps_stock_repair','【返库】','【维修配件返库】'];break;
    		/*@维修进度*/
    		case '/log/repairlog/add': return ['mps_repair_log','【添加】','【维修进度添加】'];break;
    		case '/log/repairlog/del': return ['mps_repair_log','【删除】','【维修进度删除】'];break;
    		/*@短信管理*/
    		case '/message/message/add': return ['mps_message','【添加】','【短信添加】'];break;
    		case '/message/message/del': return ['mps_message','【删除】','【短信删除】'];break;
    		case '/message/message/edit': return ['mps_message','【编辑】','【短信编辑】'];break;
    		/*@财务管理-支出分类*/
    		case '/finance/cate/add': return ['mps_expend_cate','【添加】','【支出分类添加】'];break;
    		case '/finance/cate/del': return ['mps_expend_cate','【删除】','【支出分类删除】'];break;
    		case '/finance/cate/edit': return ['mps_expend_cate','【编辑】','【支出分类编辑】'];break;
    		/*@财务管理-支出记账*/
    		case '/finance/pay/add': return ['mps_expend_log','【添加】','【支出记账添加】'];break;
    		case '/finance/pay/del': return ['mps_expend_log','【删除】','【支出记账删除】'];break;
    		/*@财务管理-退款记账*/
    		case '/finance/refund/add': return ['mps_refund_booking','【添加】','【退款记账添加】'];break;
    		case '/finance/refund/del': return ['mps_refund_booking','【删除】','【退款记账删除】'];break;
    		/*@支付记录*/
    		case '/log/paylog/add': return ['mps_order_pay_log','【添加】','【支付记录添加】'];break;
    		/*@客户管理*/
    		case '/user/user/edit': return ['mps_user','【编辑】','【客户编辑】'];break;
            /*@打印管理*/
            case '/printing/printing/edit': return ['mps_printing','【编辑】','【打印设置】'];break;
    		default: return [];break;
    	}
    }
}